package com.situ.mall.controller;

import com.situ.imall.util.JSONResult;
import com.situ.mall.pojo.User;
import com.situ.mall.service.IUserService;
import com.situ.mall.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/8/26 11:48
 **/
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/checkUserLogin")
    @ResponseBody
    //判断登录
    public JSONResult checkUserLogin(HttpSession session) {
        User user = (User) session.getAttribute("user");
        return user == null ? JSONResult.error() : JSONResult.ok();
    }

    @RequestMapping("/login")
    @ResponseBody
    public JSONResult login(@RequestParam Map params, HttpSession session) {

        return userService.login(params, session);

    }
    @RequestMapping("/loginout")
    @ResponseBody
    public JSONResult loginout(@RequestParam Map params, HttpSession session) {
        //测试主分支的提交
        return userService.login(params, session);

    }

    @RequestMapping("/getLoginPage")
    public String getLoginPage() {

        return "login";

    }

}
